//
//  Get_Handle_GetUnHandleList_Task.m
//  EpointFrame5
//
//  Created by 李亚春 on 14-2-8.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "Get_Handle_GetUnHandleList_Task.h"
#import "EpointUnHandleListModel.h"

@implementation Get_Handle_GetUnHandleList_Task

-(void)execute
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");
    NSString *userguid = [userDefaults objectForKey:Epoint_User_UserGuid];
    NSString *pagesize = [params objectForKey:@"pagesize"];
    NSString *keyword = [params objectForKey:@"keyword"];
    NSString *CurrentPageIndex = [params objectForKey:@"CurrentPageIndex"];
    NSString *HandleType = [params objectForKey:@"HandleType"];
    EpointWebServiceUtil *ws = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"Handle_GetUnHandleList"];
    
    NSString *ParasXml = @"<![CDATA[<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><KeyWord>%@</KeyWord><HandleType>%@</HandleType><CurrentPageIndex>%@</CurrentPageIndex><PageSize>%@</PageSize></paras>]]>";
    
    keyword = [EpointStringUtil filterXmlString:keyword];
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,keyword,HandleType,CurrentPageIndex,pagesize];
    [ws addParameterForString:@"ValidateData" value:ValidateData];
    [ws addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = ws.start;
    
    if ([self validateXMLWS:bs]) {
        [self exeSuccessWithData:[self getLst:bs]];
    }
}

-(NSMutableArray *)getLst:(NSString *)_xml
{
    NSString *xmldata = [EpointStringUtil getXMLFormatedAttributeBsWithTag:_xml xmlTag:@"HandleList"];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:xmldata  options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"Handle"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        EpointUnHandleListModel *m = [[EpointUnHandleListModel alloc]init];
        GDataXMLElement *MessageItemGuid = [[arr elementsForName:@"MessageItemGuid"] objectAtIndex:0];
        m.MessageItemGuid = [MessageItemGuid stringValue];
        
        GDataXMLElement *Title = [[arr elementsForName:@"Title"] objectAtIndex:0];
        m.Title = [Title stringValue];
        
        GDataXMLElement *ArchiveNo = [[arr elementsForName:@"ArchiveNo"] objectAtIndex:0];
        m.ArchiveNo = [ArchiveNo stringValue];
        
        GDataXMLElement *FromDispName = [[arr elementsForName:@"FromDispName"] objectAtIndex:0];
        m.FromDispName = [FromDispName stringValue];
        
        GDataXMLElement *GenerateDate = [[arr elementsForName:@"GenerateDate"] objectAtIndex:0];
        m.GenerateDate = [GenerateDate stringValue];
        
        GDataXMLElement *ClientIdentifier = [[arr elementsForName:@"ClientIdentifier"] objectAtIndex:0];
        m.ClientIdentifier = [ClientIdentifier stringValue];
        
        GDataXMLElement *CanHanle = [[arr elementsForName:@"CanHanle"] objectAtIndex:0];
        m.CanHanle = [CanHanle stringValue];
        
        GDataXMLElement *FileType = [[arr elementsForName:@"FileType"] objectAtIndex:0];
        m.FileType = [FileType stringValue];
        
        [listmp addObject:m];
    }
    
    return listmp;
}

@end
